

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/Mine.jpg">
  <link rel="icon" href="/img/Mine.jpg">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Chiam">
  <meta name="keywords" content="算法，安全">
  
    <meta name="description" content="『数据库』学数据库你竟然不用用 JAVA 写代码，可惜你遇到了我！ JAVA 连接数据库（JDBC）的安装使用教程Step 1 你得有 Eclipse没有出门右拐，我教不了你。 Step 2 你得有 MysqlMySQL 的详细安装过程，我在另一篇博客中给出。戳我 Step 3 安装 JDBC可以去官网下，如果用的我的 Mysql 版本的话，可以直接下我的，我的是.19下载地址如果不是，给出官网下">
<meta property="og:type" content="article">
<meta property="og:title" content="『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程">
<meta property="og:url" content="http://example.com/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E5%AD%A6%E6%95%B0%E6%8D%AE%E5%BA%93%E4%BD%A0%E7%AB%9F%E7%84%B6%E4%B8%8D%E7%94%A8%E7%94%A8JAVA%E5%86%99%E4%BB%A3%E7%A0%81%EF%BC%8C%E5%8F%AF%E6%83%9C%E4%BD%A0%E9%81%87%E5%88%B0%E4%BA%86%E6%88%91%EF%BC%81%20JAVA%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%88JDBC%EF%BC%89%E7%9A%84%E5%AE%89%E8%A3%85%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/index.html">
<meta property="og:site_name" content="Chiam 的个人主页">
<meta property="og:description" content="『数据库』学数据库你竟然不用用 JAVA 写代码，可惜你遇到了我！ JAVA 连接数据库（JDBC）的安装使用教程Step 1 你得有 Eclipse没有出门右拐，我教不了你。 Step 2 你得有 MysqlMySQL 的详细安装过程，我在另一篇博客中给出。戳我 Step 3 安装 JDBC可以去官网下，如果用的我的 Mysql 版本的话，可以直接下我的，我的是.19下载地址如果不是，给出官网下">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401102343605.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401102537155.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020040111392552.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401104914978.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401104244614.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020040110450467.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401104718420.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401104759379.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401105248374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401110244805.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020040111032248.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401110343470.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401110437864.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2020040111294997.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20200401113105361.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
<meta property="article:published_time" content="2023-12-05T16:11:43.857Z">
<meta property="article:modified_time" content="2023-12-05T16:18:09.927Z">
<meta property="article:author" content="Chiam">
<meta property="article:tag" content="算法，安全">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/20200401102343605.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70">
  
  
  
  <title>『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程 - Chiam 的个人主页</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  



  
<link rel="stylesheet" href="/css/custom.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":"❡"},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":2},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Chiam&#39;s Blogs</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                
                <span>首页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-12-06 00:11" pubdate>
          2023年12月6日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.4k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          62 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="『数据库』学数据库你竟然不用用-JAVA-写代码，可惜你遇到了我！-JAVA-连接数据库（JDBC）的安装使用教程"><a href="#『数据库』学数据库你竟然不用用-JAVA-写代码，可惜你遇到了我！-JAVA-连接数据库（JDBC）的安装使用教程" class="headerlink" title="『数据库』学数据库你竟然不用用 JAVA 写代码，可惜你遇到了我！ JAVA 连接数据库（JDBC）的安装使用教程"></a>『数据库』学数据库你竟然不用用 JAVA 写代码，可惜你遇到了我！ JAVA 连接数据库（JDBC）的安装使用教程</h1><h4 id="Step-1-你得有-Eclipse"><a href="#Step-1-你得有-Eclipse" class="headerlink" title="Step 1 你得有 Eclipse"></a>Step 1 你得有 Eclipse</h4><p>没有出门右拐，我教不了你。<br><img src="https://img-blog.csdnimg.cn/20200401102343605.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h4 id="Step-2-你得有-Mysql"><a href="#Step-2-你得有-Mysql" class="headerlink" title="Step 2 你得有 Mysql"></a>Step 2 你得有 Mysql</h4><p><strong>MySQL 的详细安装过程，我在另一篇博客中给出。</strong><a target="_blank" rel="noopener" href="https://blog.csdn.net/weixin_43627118/article/details/105027047">戳我</a><br><img src="https://img-blog.csdnimg.cn/20200401102537155.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h4 id="Step-3-安装-JDBC"><a href="#Step-3-安装-JDBC" class="headerlink" title="Step 3 安装 JDBC"></a>Step 3 安装 JDBC</h4><p>可以去官网下，如果用的我的 Mysql 版本的话，可以直接下我的，我的是.19<a target="_blank" rel="noopener" href="https://share.weiyun.com/5OXTDoz">下载地址</a><br>如果不是，给出官网<a target="_blank" rel="noopener" href="https://downloads.mysql.com/archives/c-j/">下载地址</a><br>有小伙伴私信我说，不知道那个是 Windows 的：我来解答一下。<br><img src="https://img-blog.csdnimg.cn/2020040111392552.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p><strong>1. 导入 User Library</strong><br><img src="https://img-blog.csdnimg.cn/20200401104914978.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><strong>直接拖进去就可以了</strong> <img src="https://img-blog.csdnimg.cn/20200401104244614.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/2020040110450467.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/20200401104718420.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/20200401104759379.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/20200401105248374.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><strong>2. 导入用户自订的 Library</strong><br><img src="https://img-blog.csdnimg.cn/20200401110244805.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/2020040111032248.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/20200401110343470.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/20200401110437864.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h4 id="Stept-4-数据库中来张表"><a href="#Stept-4-数据库中来张表" class="headerlink" title="Stept 4 数据库中来张表"></a>Stept 4 数据库中来张表</h4><p>相信很多道友，Mysql 都没用过，一直在吃灰。<br>我们搞张表<br><strong>打开 Mysql</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-operator">/</span><span class="hljs-operator">/</span>cmd输入，看过我之前的博客应该会了就不赘述了<br>mysql <span class="hljs-operator">-</span>uroot <span class="hljs-operator">-</span>p<br>Enter password:<br></code></pre></td></tr></table></figure>

<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><code class="hljs sql"><span class="hljs-keyword">create</span> database db;<span class="hljs-comment">--建立数据库</span><br><br> use db;<span class="hljs-keyword">create</span> <span class="hljs-keyword">table</span> <span class="hljs-keyword">user</span>(id <span class="hljs-type">int</span>, name <span class="hljs-type">varchar</span>(<span class="hljs-number">20</span>));<span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> <span class="hljs-keyword">user</span>(id, name) <span class="hljs-keyword">values</span> (<span class="hljs-number">1</span>, <span class="hljs-string">&#x27;hello&#x27;</span>);<span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> <span class="hljs-keyword">user</span>(id, name) <span class="hljs-keyword">values</span>(<span class="hljs-number">2</span>, <span class="hljs-string">&#x27;good&#x27;</span>); <span class="hljs-comment">--建表</span><br></code></pre></td></tr></table></figure>

<h4 id="Stept-5-检查是否成功"><a href="#Stept-5-检查是否成功" class="headerlink" title="Stept 5 检查是否成功"></a>Stept 5 检查是否成功</h4><p>在刚才的工程里</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">import</span> java.sql.*;<br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TEST</span> &#123;<br><br>	<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> &#123;<br>	    <span class="hljs-type">String</span> <span class="hljs-variable">driver</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>;  <span class="hljs-comment">//加载驱动程序，不用改</span><br>	    <span class="hljs-type">String</span> <span class="hljs-variable">username</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;root&quot;</span>; <span class="hljs-comment">//数据库用户名按自己的改改！！！！！！！！</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">password</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<span class="hljs-comment">//数据库密码按自己的改改！！！！！！！！！！！</span><br>        String Dbname=<span class="hljs-string">&quot;db&quot;</span>;<span class="hljs-comment">//以后访问自己数据库的时候按需修改，测试先用这个</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/&quot;</span>+Dbname+<span class="hljs-string">&quot;?&amp;useSSL=false&amp;serverTimezone=UTC&quot;</span>;<br>	    String coding=<span class="hljs-string">&quot;&amp;useUnicode=ture&amp;characterEncoding=UTF-8&quot;</span>;<span class="hljs-comment">//编码格式</span><br>        <span class="hljs-type">Connection</span> <span class="hljs-variable">conn</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span>&#123;<br>            Class.forName(driver);<br>            <span class="hljs-comment">//getConnection()方法，连接MySQL数据库！</span><br>            conn=DriverManager.getConnection(url+coding,username,password);<br>            <span class="hljs-keyword">if</span>(!conn.isClosed())<br>            System.out.println(<span class="hljs-string">&quot;-------------------------------数据库连接成功！---------------------------&quot;</span>);<br>             <span class="hljs-comment">//创建statement类对象，用来执行SQL语句！</span><br>            Statement Statement=conn.createStatement();<br>            <span class="hljs-comment">//要执行的SQL语句</span><br>            String sql=<span class="hljs-string">&quot;select * from user&quot;</span> ;<br>            <span class="hljs-comment">//ResultSet类，用来存放获取的结果集！</span><br>            ResultSet rs=Statement.executeQuery(sql);<br>            <span class="hljs-keyword">while</span>(rs.next())&#123;<br>            	System.out.println(rs.getString(<span class="hljs-string">&quot;name&quot;</span>));<br>            &#125;<br><br>         &#125;<br>         <span class="hljs-keyword">catch</span>(ClassNotFoundException e)&#123;<br>             <span class="hljs-comment">//数据库驱动类异常处理</span><br>        System.out.println(<span class="hljs-string">&quot;数据库驱动加载失败！&quot;</span>);<br>        e.printStackTrace();<br>         &#125;<br>        <span class="hljs-keyword">catch</span>(SQLException e1)&#123;<br>        <span class="hljs-comment">//数据库连接失败异常处理</span><br>         e1.printStackTrace();<br>        &#125;<br>        <span class="hljs-keyword">catch</span>(Exception e2)&#123;<br>        e2.printStackTrace();<br>        &#125;<br>        <span class="hljs-keyword">finally</span>&#123;<br>            System.out.println(<span class="hljs-string">&quot;-------------------------------数据库数据获取成功！---------------------------&quot;</span>);<br>        &#125;<br>	&#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/2020040111294997.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><font size=10 color=red>完成跑路！！！<br><img src="https://img-blog.csdnimg.cn/20200401113105361.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MzYyNzExOA==,size_16,color_FFFFFF,t_70" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h4 id="Step-6-增删查改模板："><a href="#Step-6-增删查改模板：" class="headerlink" title="Step 6 增删查改模板："></a>Step 6 增删查改模板：</h4><h5 id="1-增"><a href="#1-增" class="headerlink" title="1.增"></a>1.增</h5><p>如果不能成功链接数据库，我的博客 JAVA 中有详细的介绍，可以看一下</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">import</span> java.sql.Connection;<br><span class="hljs-keyword">import</span> java.sql.DriverManager;<br><span class="hljs-keyword">import</span> java.sql.PreparedStatement;<br><span class="hljs-keyword">import</span> java.sql.Statement;  <span class="hljs-comment">//当如相关驱动包</span><br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Add</span> &#123;<br><br>	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-type">static</span> <span class="hljs-type">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> throws Exception </span>&#123;<br><br>	    String driver = <span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>;  <span class="hljs-comment">//加载驱动程序，不用改</span><br>	    String userName = <span class="hljs-string">&quot;root&quot;</span>; <span class="hljs-comment">//数据库用户名按自己的改改！！！！！！！！</span><br>        String userPwd = <span class="hljs-string">&quot;&quot;</span>;<span class="hljs-comment">//数据库密码按自己的改改！！！！！！！！！！！</span><br>        String Dbname=<span class="hljs-string">&quot;students&quot;</span>;<span class="hljs-comment">//以后访问自己数据库的时候按需修改，测试先用这个</span><br>        String url = <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/&quot;</span>+Dbname+<span class="hljs-string">&quot;?&amp;useSSL=false&amp;serverTimezone=UTC&quot;</span>;<br>	    String coding=<span class="hljs-string">&quot;&amp;useUnicode=ture&amp;characterEncoding=UTF-8&quot;</span>;<span class="hljs-comment">//编码格式</span><br>		url = url+coding; <span class="hljs-comment">// 形成带数据库读写编码的数据库连接字</span><br><br>		Class.forName(driver); <span class="hljs-comment">// 加载并注册驱动程序</span><br>		Connection conn = DriverManager.<span class="hljs-built_in">getConnection</span>(url, userName, userPwd);<span class="hljs-comment">// 创建连接对象</span><br>		<span class="hljs-keyword">if</span> (!conn.<span class="hljs-built_in">isClosed</span>())<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;Succeeded connecting to the Database!&quot;</span>);<br>		<span class="hljs-comment">//Statement stmt = conn.createStatement();// 现在很少有人用了，部分老师比较古板，所以你不写可能会扣分的呀。笑哭</span><br><br>		<span class="hljs-comment">// 更新（添加、删除、修改）数据库操作</span><br>		String sql = <span class="hljs-string">&quot;insert into stu(xh,name,cj) values(2,&#x27;李四&#x27;,98)&quot;</span>;<br>		PreparedStatement pstmt = conn.<span class="hljs-built_in">prepareStatement</span>(sql);<br>		<span class="hljs-type">int</span> n = pstmt.<span class="hljs-built_in">executeUpdate</span>(sql);<span class="hljs-comment">// 返回记录操作条数</span><br><br>		<span class="hljs-keyword">if</span> (n &gt; <span class="hljs-number">0</span>) &#123;<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;添加记录成功，共添加了&quot;</span> + n + <span class="hljs-string">&quot;条记录&quot;</span>);<br>		&#125; <span class="hljs-keyword">else</span> &#123;<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;添加不成功！&quot;</span>);<br>		&#125;<br>		pstmt.<span class="hljs-built_in">close</span>();<br>	<span class="hljs-comment">//	stmt.close();</span><br>		conn.<span class="hljs-built_in">close</span>();<br><br>	&#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="2-删"><a href="#2-删" class="headerlink" title="2.删"></a>2.删</h5><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">import</span> java.sql.Connection;<br><span class="hljs-keyword">import</span> java.sql.DriverManager;<br><span class="hljs-keyword">import</span> java.sql.PreparedStatement;<br><span class="hljs-keyword">import</span> java.sql.Statement;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Delete</span> &#123;<br><br>	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-type">static</span> <span class="hljs-type">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> throws Exception </span>&#123;<br><br>		String driverName = <span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>; <span class="hljs-comment">// 驱动程序名</span><br>		String userName = <span class="hljs-string">&quot;root&quot;</span>; <span class="hljs-comment">// 数据库用户名</span><br>		String userPwd = null; <span class="hljs-comment">// 密码</span><br>		String dbName = <span class="hljs-string">&quot;students&quot;</span>; <span class="hljs-comment">// 数据库名</span><br>		String url = <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/&quot;</span> + dbName + <span class="hljs-string">&quot;?useSSL=false&amp;serverTimezone=UTC&quot;</span>; <span class="hljs-comment">// 形成带数据库读写编码的数据库连接字</span><br><br>		Class.forName(driverName); <span class="hljs-comment">// 加载并注册驱动程序</span><br>		Connection conn = DriverManager.<span class="hljs-built_in">getConnection</span>(url, userName, userPwd);<span class="hljs-comment">// 创建连接对象</span><br>		<span class="hljs-keyword">if</span> (!conn.<span class="hljs-built_in">isClosed</span>())<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;Succeeded connecting to the Database!&quot;</span>);<br>		Statement stmt = conn.<span class="hljs-built_in">createStatement</span>();<span class="hljs-comment">// 在桥conn上直接创建一辆汽车</span><br><br><br><br>		String sql = <span class="hljs-string">&quot;delete from stu where cj&lt;?&quot;</span>;  <span class="hljs-comment">//用占位符设置SQL操作的模板</span><br>		PreparedStatement pstmt = conn.<span class="hljs-built_in">prepareStatement</span>(sql);  <span class="hljs-comment">//预处理相关SQL语句</span><br>		<span class="hljs-type">int</span> n = stmt.<span class="hljs-built_in">executeUpdate</span>(sql);<span class="hljs-comment">// 返回记录操作条数</span><br><br>		<span class="hljs-comment">// pstmt.setInt(1,60);</span><br><br>		<span class="hljs-keyword">if</span> (n &gt; <span class="hljs-number">0</span>) &#123;<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;删除记录成功，共删除了&quot;</span> + n + <span class="hljs-string">&quot;条记录&quot;</span>);<br>		&#125; <span class="hljs-keyword">else</span> &#123;<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;删除不成功！&quot;</span>);<br>		&#125;<br>		pstmt.<span class="hljs-built_in">close</span>();<br>		stmt.<span class="hljs-built_in">close</span>();<br>		conn.<span class="hljs-built_in">close</span>();<br><br>	&#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h5 id="3-查"><a href="#3-查" class="headerlink" title="3.查"></a>3.查</h5><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><br><span class="hljs-keyword">import</span> java.sql.Connection;<br><span class="hljs-keyword">import</span> java.sql.DriverManager;<br><span class="hljs-keyword">import</span> java.sql.PreparedStatement;<br><span class="hljs-keyword">import</span> java.sql.ResultSet;<br><span class="hljs-keyword">import</span> java.sql.Statement;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Select</span> &#123;<br><br>	<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-type">static</span> <span class="hljs-type">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> throws Exception </span>&#123;<br><br>		String driverName = <span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>; <span class="hljs-comment">// 驱动程序名</span><br>		String userName = <span class="hljs-string">&quot;root&quot;</span>; <span class="hljs-comment">// 数据库用户名</span><br>		String userPwd = <span class="hljs-string">&quot;&quot;</span>; <span class="hljs-comment">// 密码</span><br>		String dbName = <span class="hljs-string">&quot;students&quot;</span>; <span class="hljs-comment">// 数据库名</span><br>		String url = <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/&quot;</span> + dbName + <span class="hljs-string">&quot;?useSSL=false&amp;serverTimezone=UTC&quot;</span>; <span class="hljs-comment">// 形成带数据库读写编码的数据库连接字</span><br><br>		Class.forName(driverName); <span class="hljs-comment">// 加载并注册驱动程序</span><br>		Connection conn = DriverManager.<span class="hljs-built_in">getConnection</span>(url, userName, userPwd);<span class="hljs-comment">// 创建连接对象</span><br>		<span class="hljs-keyword">if</span> (!conn.<span class="hljs-built_in">isClosed</span>())<br>			System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;Succeeded connecting to the Database!&quot;</span>);<br>		Statement stmt = conn.<span class="hljs-built_in">createStatement</span>();<span class="hljs-comment">// 在桥conn上直接创建一辆汽车</span><br><br>		String sql = <span class="hljs-string">&quot;select * from stu where cj&gt;=0 and cj&lt;=100&quot;</span>;<br>		PreparedStatement pstmt = conn.<span class="hljs-built_in">prepareStatement</span>(sql);<br><br>		ResultSet rs = pstmt.<span class="hljs-built_in">executeQuery</span>();<span class="hljs-comment">// 执行，得到查询结果集合</span><br>		System.out.<span class="hljs-built_in">println</span>(<span class="hljs-string">&quot;记录号	 学号		姓名		成绩&quot;</span>);<br>		<span class="hljs-keyword">while</span> (rs.<span class="hljs-built_in">next</span>()) &#123;<br>			<span class="hljs-type">int</span> a = rs.<span class="hljs-built_in">getRow</span>();<br>			<span class="hljs-type">int</span> b = rs.<span class="hljs-built_in">getInt</span>(<span class="hljs-string">&quot;xh&quot;</span>);<br>			String c = rs.<span class="hljs-built_in">getString</span>(<span class="hljs-string">&quot;name&quot;</span>);<br>			<span class="hljs-type">int</span> d = rs.<span class="hljs-built_in">getInt</span>(<span class="hljs-string">&quot;cj&quot;</span>);<br>			System.out.<span class="hljs-built_in">println</span>(a + <span class="hljs-string">&quot; | &quot;</span> + b + <span class="hljs-string">&quot; | &quot;</span> + c + <span class="hljs-string">&quot; | &quot;</span> + d);<br>		&#125;<br><br>		pstmt.<span class="hljs-built_in">close</span>();<br>		stmt.<span class="hljs-built_in">close</span>();<br>		conn.<span class="hljs-built_in">close</span>();<br><br>	&#125;<br><br>&#125;<br><br></code></pre></td></tr></table></figure>

<h5 id="4-改"><a href="#4-改" class="headerlink" title="4.改"></a>4.改</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs java">```cpp<br><br><span class="hljs-keyword">import</span> java.sql.Connection;<br><span class="hljs-keyword">import</span> java.sql.DriverManager;<br><span class="hljs-keyword">import</span> java.sql.PreparedStatement;<br><span class="hljs-keyword">import</span> java.sql.Statement;<br><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Updata</span> &#123;<br><br>	<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> <span class="hljs-keyword">throws</span> Exception &#123;<br><br>		<span class="hljs-type">String</span> <span class="hljs-variable">driverName</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;com.mysql.cj.jdbc.Driver&quot;</span>; <span class="hljs-comment">// 驱动程序名不需要修改</span><br>		<span class="hljs-type">String</span> <span class="hljs-variable">userName</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;root&quot;</span>; <span class="hljs-comment">// 数据库用户名</span><br>		<span class="hljs-type">String</span> <span class="hljs-variable">userPwd</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>; <span class="hljs-comment">// 密码</span><br>		<span class="hljs-type">String</span> <span class="hljs-variable">dbName</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;students&quot;</span>; <span class="hljs-comment">// 数据库名</span><br>		<span class="hljs-type">String</span> <span class="hljs-variable">url</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;jdbc:mysql://localhost:3306/&quot;</span> + dbName + <span class="hljs-string">&quot;?useSSL=false&amp;serverTimezone=UTC&quot;</span>; <span class="hljs-comment">// 形成带数据库读写编码的数据库连接字</span><br><br>		Class.forName(driverName); <span class="hljs-comment">// 加载并注册驱动程序</span><br>		<span class="hljs-type">Connection</span> <span class="hljs-variable">conn</span> <span class="hljs-operator">=</span> DriverManager.getConnection(url, userName, userPwd);<span class="hljs-comment">// 创建连接对象</span><br>		<span class="hljs-keyword">if</span> (!conn.isClosed())<br>			System.out.println(<span class="hljs-string">&quot;Succeeded connecting to the Database!&quot;</span>);<br>		<span class="hljs-type">Statement</span> <span class="hljs-variable">stmt</span> <span class="hljs-operator">=</span> conn.createStatement();<span class="hljs-comment">// 在桥conn上直接创建一辆汽车</span><br><br>		<span class="hljs-comment">// 更新（添加、删除、修改）数据库操作</span><br>		<span class="hljs-type">String</span> <span class="hljs-variable">sql</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;update stu set cj=? where xh=3&quot;</span>;<br>		<span class="hljs-type">PreparedStatement</span> <span class="hljs-variable">pstmt</span> <span class="hljs-operator">=</span> conn.prepareStatement(sql);<br>		<span class="hljs-type">int</span> <span class="hljs-variable">n</span> <span class="hljs-operator">=</span> stmt.executeUpdate(sql);<span class="hljs-comment">// 返回记录操作条数</span><br><br><span class="hljs-comment">//			pstmt.setInt(1,50);</span><br><span class="hljs-comment">//			pstmt.setInt(2,3);</span><br><br>		<span class="hljs-keyword">if</span> (n &gt; <span class="hljs-number">0</span>) &#123;<br>			System.out.println(<span class="hljs-string">&quot;修改记录成功，共修改了&quot;</span> + n + <span class="hljs-string">&quot;条记录&quot;</span>);<br>		&#125; <span class="hljs-keyword">else</span> &#123;<br>			System.out.println(<span class="hljs-string">&quot;修改不成功！&quot;</span>);<br>		&#125;<br>		pstmt.close();<br>		stmt.close();<br>		conn.close();<br><br>	&#125;<br><br>&#125;<br><br></code></pre></td></tr></table></figure>

<br>
<br>
<br>

<blockquote>
<p><strong>写在最后：</strong><br>我叫风骨散人，名字的意思是我多想可以不低头的自由生活，可现实却不是这样。家境贫寒，总得向这个世界低头，所以我一直在奋斗，想<code>改变我的命运</code>给亲人好的生活，希望<code>同样被生活绑架的你</code>可以通过自己的努力改变现状，深知成年人的世界里没有容易二字。目前是一名在校大学生，预计考研，热爱编程，热爱技术，喜欢分享，知识无界，希望我的分享可以帮到你！<br>如果有什么想看的，可以私信我，如果在能力范围内，我会发布相应的博文！<br>谢谢大家的阅读！😘</p>
</blockquote>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" class="category-chain-item">数据库</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程</div>
      <div>http://example.com/2023/12/06/『数据库』学数据库你竟然不用用JAVA写代码，可惜你遇到了我！ JAVA连接数据库（JDBC）的安装使用教程/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Chiam</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年12月6日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E5%AD%A6%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%98%E4%B8%8D%E4%BC%9ASelect%EF%BC%8CSQL%20Select%E8%AF%A6%E8%A7%A3%EF%BC%8C%E5%8D%95%E8%A1%A8%E6%9F%A5%E8%AF%A2%E5%AE%8C%E5%85%A8%E8%A7%A3%E6%9E%90%EF%BC%9F/" title="『数据库』学数据库还不会Select，SQL Select详解，单表查询完全解析？">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">『数据库』学数据库还不会Select，SQL Select详解，单表查询完全解析？</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/12/06/%E3%80%8E%E6%95%B0%E6%8D%AE%E5%BA%93%E3%80%8F%E5%9C%B0%E8%A1%A8%E6%9C%80%E7%AE%80%E5%8D%95%E5%AE%89%E8%A3%85MySQL%E5%8F%8A%E9%85%8D%E7%BD%AE%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%8C%E6%B2%A1%E6%9C%89%E4%B9%8B%E4%B8%80/" title="『数据库』地表最简单安装MySQL及配置的方法，没有之一">
                        <span class="hidden-mobile">『数据库』地表最简单安装MySQL及配置的方法，没有之一</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/valine/1.5.1/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"fIfc7WqUDZohlQuPc2lz5mJy-MdYXbMMI","appKey":"zjlAG3ZA3o4cBHVAkjzc2Z20","path":"window.location.pathname","placeholder":"留言仅限讨论，禁止广告等行为","avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"https://fifc7wqu.api.lncldglobal.com","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          var imgSelector = '#valine .vcontent img:not(.vemoji)';
          Fluid.plugins.imageCaption(imgSelector);
          Fluid.plugins.fancyBox(imgSelector);
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <meta name="referrer" content="no-referrer" /> <footer id="footer" role="contentinfo"> <div class="divider"> <div class="wall"></div> <img class="animals" src="/img/footer_animals_new.png" srcset="/img/loading.gif" lazyload alt="Footer Animals"> </div> <div class="container" data-index="450"> <p> <a href="https://chiamzhang.github.io" target="_blank">DogEgg</a> <i class="iconfont icon-love"></i> <a href="#" target="_blank">LittePig</a> </p> <p> Powered by  <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-pen"></i> Theme  <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> </p> </div> </footer> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>




  
<script src="/js/love.js"></script>
<script src="/js/funnyTitle.js"></script>
<script src="/js/backTop.js"></script>
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/xiaoxuehua.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/wanko.model.json"},"display":{"position":"left","width":150,"height":150,"hOffset":20,"vOffset":0},"mobile":{"show":false,"scale":0.5},"react":{"opacity":0.9},"log":false});</script></body>
</html>
